cls
<#
http://www.odata.org/blog/2010/4/22/queryable-odata-metadata
    
There are some limitations with $metadata though:
It is all or nothing. Lots of metadata means a big document.
It forces the server to prepare metadata for every type in the system, forcing an up front, rather than on demand model upon the service.

It isn't queryable. So if you want to find Types that have an Address property you have to retrieve the whole EDMX and search the xml, yourself.
#>

$namespace = @{
    a = "http://www.w3.org/2005/Atom"
    e = "http://schemas.microsoft.com/ado/2008/09/edm"
    d = "http://schemas.microsoft.com/ado/2007/08/dataservices"
    r = "http://schemas.microsoft.com/ado/2007/08/dataservices/related/"
    m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
    edmx = "http://schemas.microsoft.com/ado/2007/06/edmx"
}

Function Get-ODataMetaData { Get-Content .\NetflixMetadata.xml }

Function Get-ODataNode ($XPath) {
    $metadata = [xml](Get-ODataMetaData)
    Select-Xml $metadata -Namespace $namespace -XPath $XPath | select -ExpandProperty node
}

Function Get-ODataEntityType     { Get-ODataNode "//e:Schema/e:EntityType" }
Function Get-ODataComplexType    { Get-ODataNode "//e:Schema/e:ComplexType" }
Function Get-ODataAssociation    { Get-ODataNode "//e:Schema/e:Association" }
Function Get-ODataFunctionImport { Get-ODataNode "//e:Schema/e:EntityContainer/e:FunctionImport" }
Function Get-ODataEntitySet      { Get-ODataNode "//e:Schema/e:EntityContainer/e:EntitySet" }
Function Get-ODataAssociationSet { Get-ODataNode "//e:Schema/e:EntityContainer/e:AssociationSet" }

#Get-ODataEntityType
#Get-ODataFunctionImport
#Get-ODataEntitySet
#Get-ODataAssociationSet 
#Get-ODataComplexType
#Get-ODataAssociation

Get-ODataEntityType | % {
    $data = @($_.Property) | % {
@"
        $($_.Name) = `$$($_.Name)

"@    
    }
    
@"
Function New-$($_.Name) ($('$' + ((@($_.Property) | % {"$($_.Name)"}) -join ", $"))) {
    New-Object PSObject -Property @{
$data
    }
}

"@ | Invoke-Expression
    
}